layui.define([ 'form', 'laydate', 'table','industrialTalentsApi'], function(exports) {
    var form = layui.form;
    var industrialTalentsApi = layui.industrialTalentsApi;
    var index = layui.index;
    var view = {
        init:function(){
	        Lib.initGenrealForm($("#updateForm"),form);
	        this.initSubmit();
        },
        validAll: function (f) {
            var allCheckBox = $(".validCheckBox");
            var result = true;
            allCheckBox.each(function () {
                var state = $(this).prop("checked");
                result = result & state;
                if (state == false) {
                    $(this).focus();
                }

            });

            if (result == true) {
                f();
            } else {
                Common.info("必须勾选所有检查确认框");
            }

            return result;
        },
        initSubmit:function(){
            var _this = this;
            $("#updateButton").click(function(){
                form.on('submit(form)', function(){
                    industrialTalentsApi.updateIndustrialTalents($('#updateForm'),function(){
                       parent.window.dataReload();
                       Common.info("更新成功");
                       Lib.closeFrame();
                    });
                });
            });
            $("#updateButton-cancel").click(function(){
                Lib.closeFrame();
            });
            $("#updateButton").click(function(){
                form.on('submit(form)', function(){
                    /**
                     * 获取身份证文件
                     */

                    var isEmpty = Common.fileRequire("#IdfileDataList");
                    var payList = Common.fileRequire("#payListDataList");
                    var taxProof = Common.fileRequire("#taxProofDataList");
                    var bankCardNumberProve = Common.fileRequire("#bankCardNumberProveDataList");
                    var otherMaterials = Common.fileRequire("#otherMaterialsDataList");
                    //  var laborContract = Common.fileRequire("laborContractDataList");

                    if (isEmpty) {
                        Common.alert("身份证件附件必须上传");
                    }else if (payList) {
                        Common.alert("纳税清单附件必须上传");
                    }else if (taxProof) {
                        Common.alert("完税证明附件必须上传");
                    }else if (bankCardNumberProve) {
                        Common.alert("银行卡材料信息附件必须上传");
                    }else {
                        industrialTalentsApi.editandsave($('#updateForm'), function () {
                            parent.window.dataReload();
                            Common.info("编辑保存成功");
                            Lib.closeFrame();
                        });
                    }
                });
            });

            $("#updateButton-PandD").click(function(){
                form.on('submit(form)', function(){
                    /**
                     * 获取身份证文件
                     */

                    var isEmpty = Common.fileRequire("#IdfileDataList");
                    var payList = Common.fileRequire("#payListDataList");
                    var taxProof = Common.fileRequire("#taxProofDataList");
                    var bankCardNumberProve = Common.fileRequire("#bankCardNumberProveDataList");
                    var otherMaterials = Common.fileRequire("#otherMaterialsDataList");
                    //  var laborContract = Common.fileRequire("laborContractDataList");

                    if (isEmpty) {
                        Common.alert("身份证件附件必须上传");
                    }else if (payList) {
                        Common.alert("纳税清单附件必须上传");
                    }else if (taxProof) {
                        Common.alert("完税证明附件必须上传");
                    }else if (bankCardNumberProve) {
                        Common.alert("银行卡材料信息附件必须上传");
                    }else {
                        Common.openConfirm("确认申报?", function () {
                            industrialTalentsApi.editorialapplication($('#updateForm'), function () {
                                parent.window.dataReload();
                                Common.info("编辑申报成功");
                                Lib.closeFrame();
                            });
                        }, null);
                    }
                });
            });

            $("#acceptance-termination").click(function(){
                    form.on('submit(form)', function(){
                        Common.openConfirm("确认终止?", function () {
                            industrialTalentsApi.Admissibility($('#Acceptancelist'),function(){
                                parent.window.dataReload();
                                Common.info("已终止");
                                Lib.closeFrame();
                            });}, null)
                    });


            });
            $("#acceptance-return").click(function(){

                    form.on('submit(form)', function(){
                        Common.openConfirm("确认退回?", function () {
                            industrialTalentsApi.AdmissibleReturn($('#Acceptancelist'),function(){
                                parent.window.dataReload();
                                Common.info("已退回");
                                Lib.closeFrame();
                            });
                        }, null)
                    });

            });
            $("#acceptance-adopt").click(function(){
                if(document.getElementById("handlingSuggestion").value.trim() == ''){                 $("#handlingSuggestion").val("通过");             }


                var f = function(){
                    form.on('submit(form)', function(){
                        Common.openConfirm("确认通过?", function () {
                            industrialTalentsApi.AcceptanceOK($('#Acceptancelist'),function(){
                                parent.window.dataReload();
                                Common.info("已通过");
                                Lib.closeFrame();
                            });}, null)
                    });
                }
                Common.validAll(f);

            });
        }
    }
    exports('edit',view);
	
});